def BinarySearch(nums, target):  
    left, right = 0, len(nums) - 1  
      
    while left <= right:  
        mid = left + (right - left) // 2  
          
        if nums[mid] == target:  
            return mid  
        elif nums[mid] < target:  
            left = mid + 1  
        else:  
            right = mid - 1  
      
    return None

# 示例 1  
nums1 = [-1, 0, 3, 5, 9, 12]  
print(BinarySearch(nums1, 4))
print(BinarySearch(nums1, -1))
print(BinarySearch(nums1, 3))
print(BinarySearch(nums1, 12))
  